home *** CD-ROM | disk | FTP | other *** search
/ SunSoft Catalyst CDWARE 1996 May to August / Catalyst CDWARE 1996 May to August.iso / .products / .bin / httpd / Solaris_1 / temp.pl < prev    next >
Perl Script  |  1996-02-29  |  4KB  |  145 lines

  1. #!./perl
  2. #
  3. # newwais.pl -- WAIS search interface
  4. #
  5. # from wais.pl
  6. #
  7. # Tony Sanders <sanders@bsdi.com>, Nov 1993
  8. #
  9. # Example configuration (in local.conf):
  10. #     map topdir wais.pl &do_wais($top, $path, $query, "database", "title")
  11. #
  12. # this script uses a sneaky feature of Mosaic that interpretes a 
  13. # single text input form with the name 'isindex' (case sensitive) to
  14. # the same as a <ISINDEX>.  On non-mosaic clients, you wind up with an
  15. # additional query
  16. #
  17. # Note that I know even less about perl than the other two people
  18. # who hacked this, so feel free to send hate mail to pjh@netcom.com
  19. # if I did something really bad (or if there is a better way of
  20. # grabbing the filename off the end of a path.
  21. #
  22.  
  23. #require 'ctime.pl';
  24.  
  25. $waisq = "./waisq";
  26. $waisd = "/cdrom/cdrom0/.products/Catalyst.Catalog/_data/opt/WWW/NCSA/httpd/cgi-bin/wais-sources";
  27.  
  28.  
  29. $src = "example";
  30. $title = "Example Data";
  31. #
  32. # file type map based on file extension, since all file types
  33. # come back type URL
  34. #
  35.  
  36. %filetype = (
  37. 'html', 'HTML File',
  38. );
  39.  
  40. #
  41. # code
  42.  
  43. sub send_index {
  44.     print "Content-type: text/html\n\n";
  45.     
  46.     print "<HEAD>\n<TITLE>Index of ", $title, "</TITLE>\n</HEAD>\n";
  47.     print "<BODY>\n<H1>", $title, "</H1>\n";
  48.  
  49.     print "This is an index of the information on this server. Please\n";
  50.     print "type a query in the search dialog.\n<P>";
  51.     print "You may use compound searches, such as: <CODE>environment AND cgi</CODE>\n";
  52.     print "<ISINDEX>";
  53. }
  54.  
  55. sub do_wais {
  56. #    local($top, $path, $query, $src, $title) = @_;
  57.  
  58. # strip the escape off of *'s
  59.     for (@ARGV){s/\\//g};
  60.  
  61.     do { &'send_index; return; } unless defined @ARGV;
  62.     local(@query) = @ARGV;
  63.     local($pquery) = join(" ", @query);
  64.  
  65. #
  66. # grab a wais source if there is one
  67. #
  68.  
  69.     local($test) = $ENV{'PATH_INFO'};
  70.     if ($test)
  71.     {
  72.     $test =~ s/\///;
  73.         $src = "catalyst_catalog";
  74.         $title = $test;
  75.     }
  76.  
  77.     print "Content-type: text/html\n\n";
  78.  
  79.     $ENV{'HOME'} = "/";
  80.     
  81.     open(WAISQ, "-|") || exec ($waisq, "-c", $waisd,
  82.                                 "-f", "-", "-S", "$src.src", "-g", @query);
  83.  
  84.     print "<HEAD>\n<TITLE>Search of ", $title, "</TITLE>\n</HEAD>\n";
  85.     print "<BODY>\n<H1>", $title, "</H1>\n";
  86.  
  87.     print "<HR><FORM method=\"GET\" action=\"/cgi-bin/newwais.pl/$src\">\n";
  88.     print "Enter keyword(s):\n";
  89.     print "<input name=\"isindex\" value=\"@query\" size=30></FORM><HR>\n";
  90.  
  91.     print "$title contains the following\n";
  92.     print "items relevant to <B>\`$pquery\':</B><P>\n";
  93.     print "<DL>\n";
  94.  
  95.     local($hits, $score, $headline, $lines, $bytes, $type, $date);
  96.  
  97.     while (<WAISQ>) {
  98.         /:score\s+(\d+)/ && ($score = $1);
  99.         /:number-of-lines\s+(\d+)/ && ($lines = $1);
  100.         /:number-of-bytes\s+(\d+)/ && ($bytes = $1);
  101.         /:type "(.*)"/ && ($type = $1);
  102.         /:headline "(.*)"/ && ($headline = $1);         # XXX
  103.         /:date "(\d+)"/ && ($date = $1, $hits++, &docdone);
  104.     }
  105.     close(WAISQ);
  106.     print "</DL>\n";
  107.  
  108.     if ($hits == 0) {
  109.         print "Nothing found.\n";
  110.     }
  111.     print "</BODY>\n";
  112. }
  113.  
  114.  
  115. sub docdone {
  116.  
  117.     if ($headline =~ /Search produced no result/) {
  118.         print "<HR>";
  119.         print $headline, "<P>\n<PRE>";
  120. # the following was &'safeopen
  121.         open(WAISCAT, "$waisd/$src.cat") || die "$src.cat: $!";
  122.         while (<WAISCAT>) {
  123.             s#(Catalog for database:)\s+.*#$1 <STRONG>$src</STRONG>#;
  124.             s#Headline:\s+(.*)#Headline: <A HREF="$1">$1</A>#;
  125.             print;
  126.         }
  127.         close(WAISCAT);
  128.         print "\n</PRE>\n";
  129.     } else {
  130.         $docname = $headline;
  131.     $docname =~ s/\.([^.]*)$//;
  132.     $extension= $1;
  133.     $docname =~ s/\/([^\/]*)$//;
  134.     $docname = $1;
  135.         print "<DT><B>$hits: </B><A HREF=\"$headline\">$docname</A>\n";
  136.         print "<DD>Score:<B> $score </B> Lines:<B> $lines </B> \
  137.                    Bytes:<B> $bytes</B>\n";
  138.         print "<DD>File Type:<B> $filetype{$extension}</B>\n";
  139.     }
  140.     $score = $headline = $lines = $bytes = $type = $date = '';
  141. }
  142.  
  143. eval '&do_wais';
  144.